package com.cdie.myschool.mapper.StudentTermReportMapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cdie.myschool.domain.entity.BookHistory;
import com.cdie.myschool.domain.entity.Calendar;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * @program:my-school
 * @ClassName:BookHistoryMapper
 * @Description:借阅记录
 * @author:毛康源
 * @data:2022-10-10 10:59
 **/
@Mapper
public interface BookHistoryMapper extends BaseMapper<BookHistory> {

    @Select("select semester_id from calendar where #{borrowingDate}>=begin_time and #{borrowingDate}<=end_time")
    Calendar getSemesterIdBook(Date borrowingDate);

    @Update("update book_borrowing_history set semester_id=#{semesterId} where reader_id=#{studentCode} and borrowing_date=#{borrowingDate}")
    int updateSemeterIdBook(@Param("semesterId") Integer semesterId, @Param("studentCode") String teacherId, @Param("borrowingDate") Date borrowingDate);

    @Select("select semester_id from calendar where #{borrowingDate}>=begin_time and #{borrowingDate}<=end_time")
    Integer getSeIdBook(Date borrowingDate);

    @Select("select count(*) from book_borrowing_history where reader_id=#{readerId} and #{returnDate}>should_return_date")
    Integer getCountOver(String readerId, Date returnDate);

    @Select("select * from book_borrowing_history where #{returnDate}>should_return_date")
    Integer getOver(Date returnDate);
}
